package com.ssy.lingxi.platform.manage.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.api.model.dto.shop.ShopMemberInfoDTO;
import com.ssy.lingxi.platform.manage.entity.base.ShopRuleDetail;
import com.ssy.lingxi.platform.manage.model.request.common.CommonIdRequest;
import com.ssy.lingxi.platform.manage.model.request.shop.ShopRuleDetailRequest;
import com.ssy.lingxi.platform.manage.service.IShopActivityService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 商城能力-自营商城管理-自营商城配置
 * @author wyx
 * @version 2.0.0
 * @date 2021-09-26
 */
@RestController
@RequestMapping("/manage/activity/shop/rule")
public class ShopRuleActivityController extends BaseController {

    @Resource
    private IShopActivityService shopActivityService;

    /**
     * 获取自营商城详情
     */
    @GetMapping("/details")
    public Wrapper<ShopRuleDetail> details(@Valid CommonIdRequest request) {
        return shopActivityService.details(request);
    }

    /**
     * 根据会员ID获取自营商城列表
     */
    @RequestMapping(value = "/findListByMemberId", method = RequestMethod.GET)
    public Wrapper<List<ShopRuleDetail>> findListByMemberId(Long memberId) {
        return shopActivityService.findListByMemberId(memberId);
    }

    /**
     * 获取自营商城列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Wrapper<List<ShopRuleDetail>> list() {
        return shopActivityService.list(getSysUser());
    }

    /**
     * 设置默认自营商城
     * @param id 商城明细id
     * @param isDefault 是否默认：0:否 1.是
     */
    @RequestMapping(value = "/updateIsDefault", method = RequestMethod.GET)
    public Wrapper<Void> updateIsDefault(@RequestParam(value = "id") Long id, @RequestParam(value = "isDefault") Integer isDefault) {
        return shopActivityService.updateIsDefault(id, isDefault);
    }

    /**
     * 修改自营商城配置信息
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Wrapper<Void> update(@RequestBody @Validated ShopRuleDetailRequest shopRuleDetailRequest) {
        return shopActivityService.update(shopRuleDetailRequest);
    }

    /**
     * 判断用户是否有自营商城
     */
    @RequestMapping(value = "/existShop", method = RequestMethod.POST)
    public Wrapper<Boolean> existShop(@RequestBody @Valid ShopMemberInfoDTO dto) {
        return shopActivityService.existShop(dto);
    }

}
